package com.example.administrator.newfragmentation.fragment.zhihu.fourth;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.example.administrator.newfragmentation.R;
import com.example.administrator.newfragmentation.fragment.zhihu.fourth.child.AvatarFragment;
import com.example.administrator.newfragmentation.fragment.zhihu.fourth.child.MeFragment;
import com.example.administrator.newfragmentation.fragmentMain.BaseZhiHuFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ZhiHuFourthFragment extends BaseZhiHuFragment {
    @Bind(R.id.fl_fourth_container_upper)
    FrameLayout flFourthContainerUpper;
    @Bind(R.id.fl_fourth_container_lower)
    FrameLayout flFourthContainerLower;
    @Bind(R.id.toolbar)
    Toolbar toolbar;

    public static ZhiHuFourthFragment newInstance() {
        ZhiHuFourthFragment fragment = new ZhiHuFourthFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.zhihu_fragment_four, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        if (savedInstanceState == null) {
            loadFragment();
        } else {
            if (findChildFragment(AvatarFragment.class) == null) {
                loadFragment();
            }
        }
    }

    private void loadFragment() {
        loadRootFragment(R.id.fl_fourth_container_upper, AvatarFragment.newInstance());
        loadRootFragment(R.id.fl_fourth_container_lower, MeFragment.newInstance());
    }

    //防止让第四个fragment回退是设置frag消失
    public void onBackToFirstFragment() {
        listener.onBackToFirstFragment();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
